<template>
  <div class="top-bar">
    <ul>
      <li>
        <button @click="goBack()">后退</button>
      </li>
      <li>
        <button @click="goForward()">前进</button>
      </li>
      <li>
        <button @click="jumpTo()">转到h1</button>
      </li>
      <li>
        <router-link to="/count">count</router-link>
      </li>
    </ul>
    <ul>
      <li class="left" v-for="(va,ka) in listLeft">
        <router-link :to="va.link" v-text="va.name"></router-link>
      </li>
      <li class="right"  v-for="(va,ka) in listRight">
        <router-link :to="va.link" v-text="va.name"></router-link>
      </li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: 'TopBar',
    data () {
      return {
        listLeft: [
          {
            link: '/',
            name: '首页'
          },
          {
            link: '/hi',
            name: 'Hi'
          },
          {
            link: '/goHome',
            name: 'goHome'
          },
          {
            link: '/hiAlias',
            name: 'Hi的别名'
          },
          {
            link: '/xxxxx',
            name: '错误链接'
          }
        ],
        listRight: [
          {
            link: {
              name: 'Hi1',
              params: {
                id: 80
              }
            },
            name: 'H1'
          },
          {
            link: {
              name: 'Hi2',
              params: {
                id: '89',
                title: 'hehe'
              }
            },
            name: 'H2'
          },
          {
            link: {
              name: 'goh2',
              params: {
                id: '1',
                title: 'hah'
              }
            },
            name: 'goh2'
          }
        ]
      }
    },
    methods: {
      goBack: function () {
        this.$router.go(-1)
      },
      goForward: function () {
        this.$router.go(1)
      },
      jumpTo: function () {
        this.$router.push('/hi')
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
  h1, h2 {
    font-weight: normal;
  }

  ul {
    list-style-type: none;
    padding: 0;
  }
  ul:after{
    content: '';
    display: block;
    clear : both;
  }

  li {
    display: inline-block;
    margin: 0 10px;
  }

  a {
    color: #42b983;
  }

</style>
